/**
 * 轮播组件
 * @type {Request}
 */
const appGlobalData = getApp().globalData;
Component({

  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    swiperList: Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    current: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    swiperchange(e) {
      this.setData({
        current:e.detail.current
      });
    },
    swipclick(e) {
      let that = this;
      let swip = that.data.swiperList[that.data.current];
      if (!swip.transUrl) {
        return
      }
      if (swip.transUrlType === 1) {
        if(swip.transUrl=='ksjf'){
          if (!appGlobalData.userInfo.mobile) {//授权了，可以获取用户信息了
            //重定向到指定的页面
            wx.showModal({
              content: '为了给您提供更好的服务，请登录后使用',
              success (res) {
                if (res.confirm) {
                  //console.log('用户点击确定')
                  wx.navigateTo({
                    url: "/pages/auth/auth"
                  });
                } else if (res.cancel) {
                  //console.log('用户点击取消')
                }
              }
            })
          }else{
            var myPluginInterface = requirePlugin('paymentIntegral');
            myPluginInterface.getLocation(wx.getStorageSync('token')).then(res => {
              console.log(res)
            })
            if(appGlobalData.customer.wxmchid){
              wx.navigateTo({
                url: 'plugin://paymentIntegral/index?openid='+wx.getStorageSync('token')+'&mch_id='+appGlobalData.customer.wxmchid,
              }) 
            }else{
              wx.showToast({
                title:'未配置商户号，请联系管理员',
                icon:'none'
              })
            }
          }
        }else{
          wx.navigateTo({
            url: '/pages/home/couponDetail/index2?stockId=' + swip.transUrl
          });
        }
      }else if (swip.transUrlType === 3) {
        wx.navigateToMiniProgram({
          appId: swip.transUrl,
          success(res) {
            console.log(res)
          },
          fail(res) {
            console.log(res)
          }
        })
      }else {
        wx.navigateTo({
          url: '/pages/home/store/webindex?transUrl=' + encodeURIComponent(swip.transUrl)
        })
      }
    },
  },

  lifetimes: {
    attached: function() {
      //没有传图片过来就使用默认图片
      if (!this.data.swiperList) {
        let swiper = [
          {fileUrl: "http://file.alipayjf.com/shop/20200302100922197.jpg"},
          {fileUrl: "http://file.alipayjf.com/shop/20200302153253225.jpg"},
          {fileUrl: "http://file.alipayjf.com/shop/20200302101503069.jpg"}
        ]
        this.setData({
          swiperList: swiper
        })
      }

    }
  },

})
